//
//  SettingTableViewController.m
//  WFChat UIKit
//
//  Created by WF Chat on 2017/10/6.
//  Copyright © 2017年 WildFireChat. All rights reserved.
//

#import "WFCSecurityTableViewController.h"
#import <WFChatClient/WFCChatClient.h>
#import "WFCChangePasswordViewController.h"
#import "WFCResetPasswordViewController.h"
#import "YGExtendChain.h"
#import "SDAutoLayout.h"

@interface WFCSecurityTableViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)UIView * inputView ;

@end

@implementation WFCSecurityTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = LocalizedString(@"AccountSafety");
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
    if (@available(iOS 15, *)) {
        self.tableView.sectionHeaderTopPadding = 0;
    }
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.tableView reloadData];
    
    [self.view addSubview:self.tableView];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 48;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

//#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"style1Cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"style1Cell"];
    }
    
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"right_arrow"]];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.section == 0) {
        cell.textLabel.text = LocalizedString(@"ChangePassword");
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    [([UIApplication sharedApplication].keyWindow ?: [UIApplication sharedApplication].windows.firstObject) addSubview:self.inputView];
    self.inputView.sd_layout.spaceToSuperView(UIEdgeInsetsMake(0, 0, 0, 0));
   
    return;
    UIAlertController* actionSheet = [UIAlertController alertControllerWithTitle:nil message:@"修改密码" preferredStyle:UIAlertControllerStyleActionSheet];
    __weak typeof(self)ws = self;
    UIAlertAction *actionCode = [UIAlertAction actionWithTitle:@"短信验证码验证" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        WFCResetPasswordViewController *vc = [[WFCResetPasswordViewController alloc] init];
        [ws.navigationController pushViewController:vc animated:YES];
    }];
    
    UIAlertAction *actionPwd = [UIAlertAction actionWithTitle:@"使用密码验证" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        WFCChangePasswordViewController *vc = [[WFCChangePasswordViewController alloc] init];
        [ws.navigationController pushViewController:vc animated:YES];
    }];
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [actionSheet addAction:actionCode];
    [actionSheet addAction:actionPwd];
    [actionSheet addAction:actionCancel];
    
    [self presentViewController:actionSheet animated:YES completion:nil];
}



- (UIView *)inputView{
    if (!_inputView) {
        _inputView = [[UIView alloc]init];
        
        _inputView.sh_chain_extend.backgroundColor([UIColor colorWithHexExtendString:@"#3F3C41" alpha:0.57]).addTarget_action(self, @selector(removeMain));

        UIView *view = [[UIView alloc]init];
        [_inputView addSubview:view];
        view.sd_layout.centerXEqualToView(self.inputView).centerYEqualToView(self.inputView).offset(-25) .widthIs(ZmScreenWidth_N() - 130) ;
        view.sh_chain_extend.backgroundColorWhite().roundSize(25);

        
        
      
   
         
         
        
      
        UIButton *btn1_c = [[UIButton alloc]init];
        [view addSubview:btn1_c];
        btn1_c.sd_layout.leftSpaceToView(view, 15).topSpaceToView(view, 20).heightIs(36).widthIs(140);
        btn1_c.sh_chain_extend.title(@"短信验证码验证").titleColor([UIColor colorWithHexExtendString:@"#2B2136"]).font_size(17).addTarget_action(self, @selector(on1Register)).contentHorizontalAlignment(UIControlContentHorizontalAlignmentLeft);
      
        UIView *lab1 = [[UIView alloc]init];
        
        [view addSubview:lab1];
        lab1.sd_layout.topSpaceToView(btn1_c, 5).leftSpaceToView(view, 5).rightSpaceToView(view, 5).heightIs(1) ;
 
        lab1.sh_chain_extend.backgroundColorLight();
        
        
        
        
        UIButton *btn1_d = [[UIButton alloc]init];
        [view addSubview:btn1_d];
        btn1_d.sd_layout.leftSpaceToView(view, 15).topSpaceToView(lab1, 10).heightIs(36).widthIs(140);
        btn1_d.sh_chain_extend.title(@"使用密码验证").titleColor([UIColor colorWithHexExtendString:@"#2B2136"]).font_size (17).addTarget_action(self, @selector(on2Register)).contentHorizontalAlignment(UIControlContentHorizontalAlignmentLeft);
        
        
        
        
        [view setupAutoHeightWithBottomView:btn1_d bottomMargin:20];
        
      
        
    }
    return _inputView;
}

- (void)on1Register  {
    [self removeMain];

    WFCResetPasswordViewController *vc = [[WFCResetPasswordViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
 
}
- (void)on2Register  {
    [self removeMain];
    WFCChangePasswordViewController *vc = [[WFCChangePasswordViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (void)removeMain
{

 
   [UIView animateWithDuration:0.15 animations:^{

       self.inputView.alpha = 0 ;
   } completion:^(BOOL finished) {
       self.inputView.hidden = YES;
       [self.inputView removeFromSuperview];
       self.inputView  = nil;

   }];
}

@end
